//
//  MTZNavigationController.swift
//  weibomtz
//
//  Created by 毛铁柱 on 16/10/19.
//  Copyright © 2016年 mtz. All rights reserved.
//

import UIKit

class MTZNavigationController: UINavigationController,UIGestureRecognizerDelegate {

        
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        //如果当前控制器有子控制器的话，执行下面方法
        if childViewControllers.count>0 {
            var title = "返回"
            if childViewControllers.count == 1 {
                //
                title = childViewControllers.first?.title ??  "返回"
            }
            //设置左边的按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgNamed: "navigationbar_back_withtext", title: title, target: self, action: #selector(MTZNavigationController.back))
            //在push的时候，隐藏底部的tabbar
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: true)
    
        
        }
    //执行返回的逻辑
    @objc private func back(){
        popViewControllerAnimated(true)
    }
    
}
